import time
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.support.wait import WebDriverWait


class text(object):
    def get_url(self):

        #添加请求头
        options = webdriver.ChromeOptions()
        options.add_argument('User-Agent="Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/78.0.3904.87 Safari/537.36"')
        # 设置浏览器大小
        options.add_argument('--headless')  # 无界面调试
        options.add_argument('--window-size=1500,1000')
        options.add_argument('--disable-infobars')

        driver = webdriver.Chrome(chrome_options=options)

        driver.get('https://shuidi.cn/company-99eef3ed35fffcef4d226377abd29edf.html?from_search=1')
        # 向cookie里添加登录后才有的信息
        driver.add_cookie({'name': 'shuidi_user_id', 'value': '736164'})
        driver.add_cookie({'name': 'shuidi_uid_token', 'value': 'a20f347a6c5f84810a9c0b928f9f3003'})
        driver.add_cookie({'name': 'user_name', 'value': '13962305396'})
        driver.get('https://shuidi.cn/company-99eef3ed35fffcef4d226377abd29edf.html?from_search=1')
        detail = driver.find_element_by_xpath('//*[@id="m111"]/div/table/tbody/tr[2]/td[2]/span[2]')
        driver.execute_script('arguments[0].click()',detail)
        法定代表人的url = driver.current_url#当前获取当前路径
        ##page_souce获取当前网页源代码
        WebDriverWait(driver, 10)

        print('法定代表人的url:'+法定代表人的url)
        time.sleep(5)
        driver.quit()

if __name__ == '__main__':
    x = text()
    x.get_url()




